// pages/index/party_work/party_work.js
const app = getApp()
const http = new app.appHttp()
const log = new app.appLogs()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    organizationlist: [],
    governmentlist: [],
    isRefreshZZ: false,
    isRefreshHD: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getOrganization()
    this.getGovernment()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /**
   * 党组织下拉刷新
   * @param e
   */
  onRefreshZZ: function (e) {
    this.setData({
      isRefreshZZ: true,
      organizationlist: []
    })
    this.getOrganization()
  },

  /**
   * 党建活动下拉刷新
   * @param e
   */
  onRefreshHD: function (e) {
    this.setData({
      isRefreshHD: true,
      governmentlist: []
    })
    this.getGovernment()
  },

  /**
   * 请求党组织列表
   * @param event
   */
  getOrganization: function (event) {
    const than = this
    this.setData({
      isLoading: true
    })
    http.get("party/getPartyOrgList", {
      area_code: app.globalData.areaCode
    }).then((res) => {
      if (res.data.code == 200) {
        than.setData({
          organizationlist: res.data.data,
        })
      }
      this.setData({
        isLoading: false,
        isRefreshZZ: false,
      })
    }, err => {
      this.setData({
        isLoading: false,
        isRefreshZZ: false,
      })
    })
  },

  /**
   * 请求党建活动列表
   * @param event
   */
  getGovernment: function (event) {
    const than = this
    http.get("party/getPartyOrgActivityList", {
      area_code: app.globalData.areaCode
    }).then((res) => {
      if (res.data.code == 200) {
        than.setData({
          governmentlist: res.data.data
        })
      }
      this.setData({
        isLoading: false,
        isRefreshHD: false,
      })
    }, err => {
      this.setData({
        isLoading: false,
        isRefreshHD: false,
      })
    })
  },

  /**
   * 党组织详情
   * @param event
   */
  onOrganizationDetails: function (event) {
    const id = event.currentTarget.dataset.id
    log.e("党组织id：" + id)
    wx.navigateTo({
      url: '../party/partydetails/partydetails?id=' + id
    })
  },

  /**
   * 党建活动详情
   * @param event
   */
  onGovernmentDetails: function (event) {
    const id = event.currentTarget.dataset.id
    log.e("党建活动id：" + id)
    wx.navigateTo({
      url: '../party/partyactivitydetails/partyactivitydetails?id=' + id
    })
  },

})